package cn.hd01.util;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;

import cn.hd01.repository.entity.User;

public class CommonUtil {
	
	public static Integer getLoginUserType(User loginUser){
		if(loginUser == null){
			return null;
		}else{
			return loginUser.getType();
		}
	}
	
	public static Integer getAge(Date birthDay) {  
		if(birthDay == null){
			return null;
		}
        Calendar cal = Calendar.getInstance();  
  
        if (cal.before(birthDay)) {  
        	return 0;
        }  
        int yearNow = cal.get(Calendar.YEAR);  
        int monthNow = cal.get(Calendar.MONTH);  
        int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH);  
        cal.setTime(birthDay);  
  
        int yearBirth = cal.get(Calendar.YEAR);  
        int monthBirth = cal.get(Calendar.MONTH);  
        int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);  
  
        int age = yearNow - yearBirth;  
  
        if (monthNow <= monthBirth) {  
            if (monthNow == monthBirth) {  
                if (dayOfMonthNow < dayOfMonthBirth) age--;  
            }else{  
                age--;  
            }  
        }  
        return age;  
    }  
	
	public static BigDecimal dealNullNumber(BigDecimal num){
		if(num == null)
			return BigDecimal.ZERO;
		
		return num;
	}
}
